package com.lxw.study.structural.proxy.dynamicproxy.cglib;

import org.springframework.cglib.proxy.Enhancer;
import org.springframework.cglib.proxy.MethodInterceptor;

public class Client {
    public static void main(String[] args) {
        Enhancer enhancer = new Enhancer();
        enhancer.setSuperclass(RealSubject.class);
        MethodInterceptor methodInterceptor = (target, method, objects, methodProxy) -> {
            System.out.println("方法前");
            Object result = methodProxy.invokeSuper(target, objects);
            System.out.println("方法后");
            return result;
        };
        enhancer.setCallback(methodInterceptor);
        Subject proxy = (Subject) enhancer.create();
        proxy.request();
    }
}
